﻿//-----------------------------------------------------------------------
// <copyright file="FakeChatDataSource.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
//----------------------------------------------------------------------- 

namespace ChatBox.Engine.Fake
{
    using System;

    using ChatBox.DomainObjects.ResultData;
    using ChatBox.Interfaces;
    using ChatBox.Utility;

    /// <summary>
    /// Stub chat data source that returns test data
    /// </summary>
    public class FakeChatDataSource : IChatDataSource
    {
        /// <summary>
        /// Has the source been started yet
        /// </summary>
        private bool isStarted;

        /// <summary>
        /// the topic to return
        /// </summary>
        private string topic;

        /// <summary>
        /// Initializes a new instance of the FakeChatDataSource class
        /// </summary>
        /// <param name="topic">the topic to return</param>
        public FakeChatDataSource(string topic)
        {
            this.topic = topic;
        }

        #region IChatDataSource Members

        /// <summary>
        /// tell listeners that new messages have arrived
        /// </summary>
        public event EventHandler<EventArgs<ChatDataResult>> DataReceived;

        /// <summary>
        /// Gets a value indicating whether the source has been started yet
        /// </summary>
        public bool IsStarted
        {
            get 
            {
                return this.isStarted;  
            }
        }

        /// <summary>
        /// Start the source
        /// </summary>
        public void Start()
        {
            this.isStarted = true;

            this.SendTopic();
        }

        /// <summary>
        /// Send the topic data
        /// </summary>
        private void SendTopic()
        {
            ChatDataResult result = new ChatDataResult(true, string.Empty);
            result.Topic = this.topic;

            if (this.DataReceived != null)
            {
                this.DataReceived(this, new EventArgs<ChatDataResult>(result));
            }
        }

        #endregion
    }
}
